package org.jsola.hr.helper;

import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.dto.SalaryBasicAddDTO;
import org.jsola.hr.dto.SalaryBasicUpdateDTO;
import org.jsola.hr.entity.SalaryBasicDO;
import org.jsola.hr.query.SalaryBasicQuery;
import org.jsola.hr.service.ISalaryBasicService;
import org.jsola.hr.vo.SalaryBasicVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工薪资表
 *
 * @author zhr
 */
@Component
public class SalaryBasicTestHelper extends BaseTestHelper {
    
    @Autowired
    private ISalaryBasicService salaryBasicService;

    /**
     * 生成add测试数据
     * @return SalaryBasicAddDTO
     */
    public SalaryBasicAddDTO getSalaryBasicAddDTO(){
        SalaryBasicAddDTO salaryBasicAddDTO = new SalaryBasicAddDTO();
        salaryBasicAddDTO.setEmpId(getRandomValue("varchar",32));
        salaryBasicAddDTO.setSalaryBasic(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBasicAddDTO.setTrafficSubsidy(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBasicAddDTO.setMealSubsidy(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBasicAddDTO.setSalaryPerformance(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBasicAddDTO.setReason(getRandomValue("varchar",255));
        salaryBasicAddDTO.setRemark(getRandomValue("varchar",1000));
        salaryBasicAddDTO.setSalaryTotal(SafeKit.getInteger(getRandomValue("int",11)));
        salaryBasicAddDTO.setCompanyId(getRandomValue("varchar",32));
        return salaryBasicAddDTO;
    }


    /**
     * 生成update测试数据
     * @return SalaryBasicUpdateDTO
     */
    public SalaryBasicUpdateDTO getSalaryBasicUpdateDTO(SalaryBasicVO salaryBasicVO){
        return salaryBasicService.selectDOById(salaryBasicVO.getId(), SITE_ID).to(SalaryBasicUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return SalaryBasicQuery
     */
    public SalaryBasicQuery getSalaryBasicQuery() {
        SalaryBasicQuery salaryBasicQuery = new SalaryBasicQuery();
        List<SalaryBasicDO> salaryBasicDOList = salaryBasicService.list(new SalaryBasicDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(salaryBasicDOList)) {
            SalaryBasicDO salaryBasicDO = salaryBasicDOList.get(0);
            salaryBasicQuery = salaryBasicDO.to(SalaryBasicQuery.class);
            if (salaryBasicDO.getGmtCreate() != null) {
                salaryBasicQuery.setGmtCreateStart(DateKit.getBeforeDay(salaryBasicDO.getGmtCreate(),-1));
                salaryBasicQuery.setGmtCreateEnd(DateKit.getBeforeDay(salaryBasicDO.getGmtCreate(),1));
            }
            if (salaryBasicDO.getGmtModified() != null) {
                salaryBasicQuery.setGmtModifiedStart(DateKit.getBeforeDay(salaryBasicDO.getGmtModified(),-1));
                salaryBasicQuery.setGmtModifiedEnd(DateKit.getBeforeDay(salaryBasicDO.getGmtModified(),1));
            }
        }
        return salaryBasicQuery;
    }

    /**
     * 保存示例
     * @return SalaryBasicVO
     */
    public SalaryBasicVO saveSalaryBasicExample(){
        SalaryBasicAddDTO addDTO = this.getSalaryBasicAddDTO();
        SalaryBasicVO salaryBasicVO = salaryBasicService.save(addDTO,buildTokenUser());
        return salaryBasicVO;
    }


}

